import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/api-bigscreen/bigscreen/project/list',
  getData = '/api-bigscreen/bigscreen/project/getData',
  save = '/api-bigscreen/bigscreen/project/add',
  edit = '/api-bigscreen/bigscreen/project/edit',
  saveData = '/api-bigscreen/bigscreen/project/saveData',
  copyPage = '/api-bigscreen/bigscreen/project/copyPage',
  delete = '/api-bigscreen/bigscreen/project/delete',
  rename = '/api-bigscreen/bigscreen/project/rename',
  publish = '/api-bigscreen/bigscreen/project/publish',
  upload = '/api-bigscreen/bigscreen/project/upload',
}

/**
 * 列表
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });
/**
 * 根据id查询
 * @param params
 */
export const getData = (params) => defHttp.get({ url: Api.getData, params }, { isTransformResponse: false });
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};
/**
 * 删除
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 复制
 */
export const copyPage = (params, handleSuccess) => {
  return defHttp.get({ url: Api.copyPage, params }, { isTransformResponse: false }).then(() => {
    handleSuccess();
  });
};

/**
 * 重命名
 */
export const rename = (params, handleSuccess) => {
  return defHttp.get({ url: Api.rename, params }, { isTransformResponse: false }).then(() => {
    handleSuccess();
  });
};

/**
 * 发布/撤消
 */
export const publish = (params, handleSuccess) => {
  return defHttp.get({ url: Api.publish, params }, { isTransformResponse: false }).then(() => {
    handleSuccess();
  });
};
